/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [BankTest.java]
 * Creation Date        [02-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_08_thread.synchronization;

/**
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class BankTest {

	public static final int NACCOUNTS = 100;
	public static final double INITIAL_BALANCE = 1000;

	/**
	 * 测试不同步银行
	 */
	public static void testUnsyncBank() {
		UnsyncBank bank = new UnsyncBank(NACCOUNTS, INITIAL_BALANCE);
		for (int i = 0; i < NACCOUNTS; i++) {
			BankRunnable r = new BankRunnable(bank, i, INITIAL_BALANCE);
			Thread t = new Thread(r);
			t.start();
		}
	}

	/**
	 * 测试同步银行
	 */
	public static void testSyncBank_V1() {
		SyncBank_V1 bank = new SyncBank_V1(NACCOUNTS, INITIAL_BALANCE);
		for (int i = 0; i < NACCOUNTS; i++) {
			BankRunnable r = new BankRunnable(bank, i, INITIAL_BALANCE);
			Thread t = new Thread(r);
			t.start();
		}
	}

	/**
	 * 测试同步银行
	 */
	public static void testSyncBank_V2() {
		SyncBank_V2 bank = new SyncBank_V2(NACCOUNTS, INITIAL_BALANCE);
		for (int i = 0; i < NACCOUNTS; i++) {
			BankRunnable r = new BankRunnable(bank, i, INITIAL_BALANCE);
			Thread t = new Thread(r);
			t.start();
		}
	}

	public static void main(String[] args) {
		// testUnsyncBank();
		// testSyncBank_V1();
		testSyncBank_V2();

	}
}
